package com.recharge.domain.context;

import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


/**
 * shiro 序列化 工具 （暂时没用）
 */
public class MyRedisSerializer{


    /**
     * 对象序列化成字符串
     */
    public static String serialize(Object obj) {
        try {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            ObjectOutputStream objectOutputStream;
            objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
            objectOutputStream.writeObject(obj);
            String string = byteArrayOutputStream.toString("ISO-8859-1");
            objectOutputStream.close();
            byteArrayOutputStream.close();
            return string;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }



    }


    /**
     *
     * 字符串序列化成Javabean
     */
    public static Object deserialize(String str)  {
        try{
            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(str.getBytes("ISO-8859-1"));
            ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
            Object object = objectInputStream.readObject();
            objectInputStream.close();
            byteArrayInputStream.close();
            return object;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;

    }
}
